home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume2 / compress4.0 / part2 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  32.2 KB

  1. From: vax135!petsd!joe (Joe Orost)
  2. Subject: Compress 4.0 (part 2 of 2)
  3. Newsgroups: mod.sources
  4. Approved: john@genrad.UUCP
  5.  
  6. Mod.sources:  Volume 2, Issue 29
  7. Submitted by: vax135!petsd!joe (Joe Orost)
  8.  
  9. #! /bin/sh
  10. # This is a shell archive, meaning:
  11. # 1. Remove everything above the #! /bin/sh line.
  12. # 2. Save the resulting text in a file.
  13. # 3. Execute the file with /bin/sh (not csh) to create the files:
  14. #    README
  15. #    README3.0
  16. #    atob.c
  17. #    btoa.1
  18. #    btoa.c
  19. #    compressdir
  20. #    compressdir.1
  21. #    tarmail
  22. #    uncompressdir
  23. #    untarmail
  24. #    zcmp
  25. #    zcmp.1
  26. #    zdiff
  27. #    zmore
  28. #    zmore.1
  29. # This archive created: Thu Aug  1 11:53:09 1985
  30. export PATH; PATH=/bin:$PATH
  31. echo shar: extracting "'README'" '(3194 characters)'
  32. if test -f 'README'
  33. then
  34.     echo shar: will not over-write existing file "'README'"
  35. else
  36. sed 's/^X//' << \SHAR_EOF > 'README'
  37. Compress version 4.0 improvements:
  38.     o compress() speedup (10-50%) by changing division hash to xor
  39.     o decompress() speedup (5-10%)
  40.     o Memory requirements reduced (3-30%)
  41.     o Stack requirements reduced to less than 4kb
  42.     o Removed 'Big+Fast' compress code (FBITS) because of compress speedup
  43.         o Portability mods for Z8000 and PC/XT (but not zeus 3.2)
  44.     o Default to 'quiet' mode
  45.     o Unification of 'force' flags
  46.     o Manual page overhaul
  47.     o Portability enhancement for M_XENIX
  48.     o Removed text on #else and #endif
  49.     o Added "-V" switch to print version and options
  50.     o Added #defines for SIGNED_COMPARE_SLOW
  51.     o Added Makefile and "usermem" program
  52.     o Removed all floating point computations
  53.     o New programs:
  54.         compressdir - compress all files on a directory
  55.         uncompressdir - uncompress all files on a directory
  56.         zcmp - cmp compressed files
  57.         zdiff - diff compressed files
  58.       The following are with thanks to philabs!per:
  59.         btoa - convert binary to ascii for mailing
  60.         atob - convert ascii to binary with checksum
  61.         tarmail - tar, compress, btoa, and mail files
  62.         untarmail - restore "tarmail" files
  63.  
  64.         WARNING: These last few programs are not compatible 
  65.         with the original ones from the net.  The encoding
  66.         has changed.  See btoa.c for more info.
  67.  
  68. The "usermem" script attempts to determine the maximum process size.  Some
  69. editing of the script may be necessary (see the comments).  If you can't get
  70. it to work at all, just create file "USERMEM" containing the maximum process
  71. size in decimal.
  72.  
  73. The following preprocessor symbols control the compilation of "compress.c":
  74.  
  75.     o USERMEM        Maximum process memory on the system
  76.     o SACREDMEM        Amount to reserve for other proceses
  77.     o SIGNED_COMPARE_SLOW    Unsigned compare instructions are faster
  78.     o NO_UCHAR        Don't use "unsigned char" types
  79.     o BITS            Overrules default set by USERMEM-SACREDMEM
  80.     o vax            Generate inline assembler
  81.     o interdata        Defines SIGNED_COMPARE_SLOW
  82.     o M_XENIX        Makes arrays < 65536 bytes each
  83.     o pdp11            BITS=12, NO_UCHAR
  84.     o z8000            BITS=12
  85.     o pcxt            BITS=12
  86.     o BSD4_2        Allow long filenames ( > 14 characters) &
  87.                 Call setlinebuf(stderr)
  88.  
  89. The difference "usermem-sacredmem" determines the maximum BITS that can be
  90. specified with the "-b" flag.
  91.  
  92. memory: at least        BITS
  93. ------  -- -----                ----
  94.      433,484             16
  95.      229,600             15
  96.      127,536             14
  97.       73,464             13
  98.            0             12
  99.  
  100. The default is BITS=16.
  101.  
  102. The maximum bits can be overrulled by specifying "-DBITS=bits" at
  103. compilation time.
  104.  
  105. WARNING: files compressed on a large machine with more bits than allowed by 
  106. a version of compress on a smaller machine cannot be decompressed!  Use the
  107. "-b12" flag to generate a file on a large machine that can be uncompressed 
  108. on a 16-bit machine.
  109.  
  110. The output of compress 4.0 is fully compatible with that of compress 3.0.
  111. In other words, the output of compress 4.0 may be fed into uncompress 3.0 or
  112. the output of compress 3.0 may be fed into uncompress 4.0.
  113.  
  114. The output of compress 4.0 not compatable with that of
  115. compress 2.0.  However, compress 4.0 still accepts the output of
  116. compress 2.0.  To generate output that is compatable with compress
  117. 2.0, use the undocumented "-C" flag.
  118.  
  119. Check the Makefile, then "make".
  120. SHAR_EOF
  121. if test 3194 -ne "`wc -c < 'README'`"
  122. then
  123.     echo shar: error transmitting "'README'" '(should have been 3194 characters)'
  124. fi
  125. fi # end of overwriting check
  126. echo shar: extracting "'README3.0'" '(8142 characters)'
  127. if test -f 'README3.0'
  128. then
  129.     echo shar: will not over-write existing file "'README3.0'"
  130. else
  131. sed 's/^X//' << \SHAR_EOF > 'README3.0'
  132. Enclosed is compress version 3.0 with the following changes:
  133.  
  134. 1.    "Block" compression is performed.  After the BITS run out, the
  135.     compression ratio is checked every so often.  If it is decreasing,
  136.     the table is cleared and a new set of substrings are generated.
  137.  
  138.     This makes the output of compress 3.0 not compatable with that of
  139.     compress 2.0.  However, compress 3.0 still accepts the output of
  140.     compress 2.0.  To generate output that is compatable with compress
  141.     2.0, use the undocumented "-C" flag.
  142.  
  143. 2.    A quiet "-q" flag has been added for use by the news system.
  144.  
  145. 3.    The character chaining has been deleted and the program now uses
  146.     hashing.  This improves the speed of the program, especially
  147.     during decompression.  Other speed improvements have been made,
  148.     such as using putc() instead of fwrite().
  149.  
  150. 4.    A large table is used on large machines when a relatively small
  151.     number of bits is specified.  This saves much time when compressing
  152.     for a 16-bit machine on a 32-bit virtual machine.  Note that the
  153.     speed improvement only occurs when the input file is > 30000
  154.     characters, and the -b BITS is less than or equal to the cutoff
  155.     described below.
  156.  
  157. Most of these changes were made by James A. Woods (ames!jaw).  Thank you
  158. James!
  159.  
  160. Version 3.0 has been beta tested on many machines.
  161.  
  162. To compile compress:
  163.  
  164.     cc -O -DUSERMEM=usermem -o compress compress.c
  165.  
  166. Where "usermem" is the amount of physical user memory available (in bytes).  
  167. If any physical memory is to be reserved for other processes, put in 
  168. "-DSACREDMEM sacredmem", where "sacredmem" is the amount to be reserved.
  169.  
  170. The difference "usermem-sacredmem" determines the maximum BITS that can be
  171. specified, and the cutoff bits where the large+fast table is used.
  172.  
  173. memory: at least        BITS        cutoff
  174. ------  -- -----                ----            ------
  175.    4,718,592              16          13
  176.    2,621,440              16          12
  177.    1,572,864             16          11
  178.    1,048,576             16          10
  179.      631,808             16               --
  180.      329,728             15               --
  181.      178,176             14          --
  182.       99,328             13          --
  183.            0             12          --
  184.  
  185. The default memory size is 750,000 which gives a maximum BITS=16 and no
  186. large+fast table.
  187.  
  188. The maximum bits can be overrulled by specifying "-DBITS=bits" at
  189. compilation time.
  190.  
  191. If your machine doesn't support unsigned characters, define "NO_UCHAR" 
  192. when compiling.
  193.  
  194. If your machine has "int" as 16-bits, define "SHORT_INT" when compiling.
  195.  
  196. After compilation, move "compress" to a standard executable location, such 
  197. as /usr/local.  Then:
  198.     cd /usr/local
  199.     ln compress uncompress
  200.     ln compress zcat
  201.  
  202. On machines that have a fixed stack size (such as Perkin-Elmer), set the
  203. stack to at least 12kb.  ("setstack compress 12" on Perkin-Elmer).
  204.  
  205. Next, install the manual (compress.l).
  206.     cp compress.l /usr/man/manl
  207.     cd /usr/man/manl
  208.     ln compress.l uncompress.l
  209.     ln compress.l zcat.l
  210.  
  211.         - or -
  212.  
  213.     cp compress.l /usr/man/man1/compress.1
  214.     cd /usr/man/man1
  215.     ln compress.1 uncompress.1
  216.     ln compress.1 zcat.1
  217.  
  218. The zmore shell script and manual page are for use on systems that have a
  219. "more(1)" program.  Install the shell script and the manual page in a "bin"
  220. and "man" directory, respectively.  If your system doesn't have the
  221. "more(1)" program, just skip "zmore".
  222.  
  223.                     regards,
  224.                     petsd!joe
  225.  
  226. Here is the README file from the previous version of compress (2.0):
  227.  
  228. >Enclosed is compress.c version 2.0 with the following bugs fixed:
  229. >
  230. >1.    The packed files produced by compress are different on different
  231. >    machines and dependent on the vax sysgen option.
  232. >        The bug was in the different byte/bit ordering on the
  233. >        various machines.  This has been fixed.
  234. >
  235. >        This version is NOT compatible with the original vax posting
  236. >        unless the '-DCOMPATIBLE' option is specified to the C
  237. >        compiler.  The original posting has a bug which I fixed, 
  238. >        causing incompatible files.  I recommend you NOT to use this
  239. >        option unless you already have a lot of packed files from
  240. >        the original posting by thomas.
  241. >2.    The exit status is not well defined (on some machines) causing the
  242. >    scripts to fail.
  243. >        The exit status is now 0,1 or 2 and is documented in
  244. >        compress.l.
  245. >3.    The function getopt() is not available in all C libraries.
  246. >        The function getopt() is no longer referenced by the
  247. >        program.
  248. >4.    Error status is not being checked on the fwrite() and fflush() calls.
  249. >        Fixed.
  250. >
  251. >The following enhancements have been made:
  252. >
  253. >1.    Added facilities of "compact" into the compress program.  "Pack",
  254. >    "Unpack", and "Pcat" are no longer required (no longer supplied).
  255. >2.    Installed work around for C compiler bug with "-O".
  256. >3.    Added a magic number header (\037\235).  Put the bits specified
  257. >    in the file.
  258. >4.    Added "-f" flag to force overwrite of output file.
  259. >5.    Added "-c" flag and "zcat" program.  'ln compress zcat' after you
  260. >    compile.
  261. >6.    The 'uncompress' script has been deleted; simply 
  262. >    'ln compress uncompress' after you compile and it will work.
  263. >7.    Removed extra bit masking for machines that support unsigned
  264. >    characters.  If your machine doesn't support unsigned characters,
  265. >    define "NO_UCHAR" when compiling.
  266. >
  267. >Compile "compress.c" with "-O -o compress" flags.  Move "compress" to a
  268. >standard executable location, such as /usr/local.  Then:
  269. >    cd /usr/local
  270. >    ln compress uncompress
  271. >    ln compress zcat
  272. >
  273. >On machines that have a fixed stack size (such as Perkin-Elmer), set the
  274. >stack to at least 12kb.  ("setstack compress 12" on Perkin-Elmer).
  275. >
  276. >Next, install the manual (compress.l).
  277. >    cp compress.l /usr/man/manl        - or -
  278. >    cp compress.l /usr/man/man1/compress.1
  279. >
  280. >Here is the README that I sent with my first posting:
  281. >
  282. >>Enclosed is a modified version of compress.c, along with scripts to make it
  283. >>run identically to pack(1), unpack(1), an pcat(1).  Here is what I
  284. >>(petsd!joe) and a colleague (petsd!peora!srd) did:
  285. >>
  286. >>1. Removed VAX dependencies.
  287. >>2. Changed the struct to separate arrays; saves mucho memory.
  288. >>3. Did comparisons in unsigned, where possible.  (Faster on Perkin-Elmer.)
  289. >>4. Sorted the character next chain and changed the search to stop
  290. >>prematurely.  This saves a lot on the execution time when compressing.
  291. >>
  292. >>This version is totally compatible with the original version.  Even though
  293. >>lint(1) -p has no complaints about compress.c, it won't run on a 16-bit
  294. >>machine, due to the size of the arrays.
  295. >>
  296. >>Here is the README file from the original author:
  297. >> 
  298. >>>Well, with all this discussion about file compression (for news batching
  299. >>>in particular) going around, I decided to implement the text compression
  300. >>>algorithm described in the June Computer magazine.  The author claimed
  301. >>>blinding speed and good compression ratios.  It's certainly faster than
  302. >>>compact (but, then, what wouldn't be), but it's also the same speed as
  303. >>>pack, and gets better compression than both of them.  On 350K bytes of
  304. >>>unix-wizards, compact took about 8 minutes of CPU, pack took about 80
  305. >>>seconds, and compress (herein) also took 80 seconds.  But, compact and
  306. >>>pack got about 30% compression, whereas compress got over 50%.  So, I
  307. >>>decided I had something, and that others might be interested, too.
  308. >>>
  309. >>>As is probably true of compact and pack (although I haven't checked),
  310. >>>the byte order within a word is probably relevant here, but as long as
  311. >>>you stay on a single machine type, you should be ok.  (Can anybody
  312. >>>elucidate on this?)  There are a couple of asm's in the code (extv and
  313. >>>insv instructions), so anyone porting it to another machine will have to
  314. >>>deal with this anyway (and could probably make it compatible with Vax
  315. >>>byte order at the same time).  Anyway, I've linted the code (both with
  316. >>>and without -p), so it should run elsewhere.  Note the longs in the
  317. >>>code, you can take these out if you reduce BITS to <= 15.
  318. >>>
  319. >>>Have fun, and as always, if you make good enhancements, or bug fixes,
  320. >>>I'd like to see them.
  321. >>>
  322. >>>=Spencer (thomas@utah-20, {harpo,hplabs,arizona}!utah-cs!thomas)
  323. >>
  324. >>                    regards,
  325. >>                    joe
  326. >>
  327. >>--
  328. >>Full-Name:  Joseph M. Orost
  329. >>UUCP:       ..!{decvax,ucbvax,ihnp4}!vax135!petsd!joe
  330. >>US Mail:    MS 313; Perkin-Elmer; 106 Apple St; Tinton Falls, NJ 07724
  331. >>Phone:      (201) 870-5844
  332. SHAR_EOF
  333. if test 8142 -ne "`wc -c < 'README3.0'`"
  334. then
  335.     echo shar: error transmitting "'README3.0'" '(should have been 8142 characters)'
  336. fi
  337. fi # end of overwriting check
  338. echo shar: extracting "'atob.c'" '(2505 characters)'
  339. if test -f 'atob.c'
  340. then
  341.     echo shar: will not over-write existing file "'atob.c'"
  342. else
  343. sed 's/^X//' << \SHAR_EOF > 'atob.c'
  344. /* atob: version 4.0
  345.  * stream filter to change printable ascii from "btoa" back into 8 bit bytes
  346.  * if bad chars, or Csums do not match: exit(1) [and NO output]
  347.  *
  348.  *  Paul Rutter        Joe Orost
  349.  *  philabs!per        petsd!joe
  350.  */
  351.  
  352. #include <stdio.h>
  353.  
  354. #define reg register
  355.  
  356. #define streq(s0, s1)  strcmp(s0, s1) == 0
  357.  
  358. #define times85(x)    ((((((x<<2)+x)<<2)+x)<<2)+x)
  359.  
  360. long int Ceor = 0;
  361. long int Csum = 0;
  362. long int Crot = 0;
  363. long int word = 0;
  364. long int bcount = 0;
  365.  
  366. fatal() {
  367.   fprintf(stderr, "bad format or Csum to atob\n");
  368.   exit(1);
  369. }
  370.  
  371. #define DE(c) ((c) - '!')
  372.  
  373. decode(c) 
  374.   reg c;
  375. {
  376.   if (c == 'z') {
  377.     if (bcount != 0) {
  378.       fatal();
  379.     } else {
  380.       byteout(0);
  381.       byteout(0);
  382.       byteout(0);
  383.       byteout(0);
  384.     }
  385.   } else if ((c >= '!') && (c < ('!' + 85))) {
  386.     if (bcount == 0) {
  387.       word = DE(c);
  388.       ++bcount;
  389.     } else if (bcount < 4) {
  390.       word = times85(word);
  391.       word += DE(c);
  392.       ++bcount;
  393.     } else {
  394.       word = times85(word) + DE(c);
  395.       byteout((int)((word >> 24) & 255));
  396.       byteout((int)((word >> 16) & 255));
  397.       byteout((int)((word >> 8) & 255));
  398.       byteout((int)(word & 255));
  399.       word = 0;
  400.       bcount = 0;
  401.     }
  402.   } else {
  403.     fatal();
  404.   }
  405. }
  406.  
  407. XFILE *tmp_file;
  408.  
  409. byteout(c) 
  410.   reg c;
  411. {
  412.   Ceor ^= c;
  413.   Csum += c;
  414.   Csum += 1;
  415.   if ((Crot & 0x80000000)) {
  416.     Crot <<= 1;
  417.     Crot += 1;
  418.   } else {
  419.     Crot <<= 1;
  420.   }
  421.   Crot += c;
  422.   putc(c, tmp_file);
  423. }
  424.  
  425. main(argc, argv) 
  426.   char **argv;
  427. {
  428.   reg c;
  429.   reg long int i;
  430.   char tmp_name[100];
  431.   char buf[100];
  432.   long int n1, n2, oeor, osum, orot;
  433.  
  434.   if (argc != 1) {
  435.     fprintf(stderr,"bad args to %s\n", argv[0]);
  436.     exit(2);
  437.   }
  438.   sprintf(tmp_name, "/usr/tmp/atob.%x", getpid());
  439.   tmp_file = fopen(tmp_name, "w+");
  440.   if (tmp_file == NULL) {
  441.     fatal();
  442.   }
  443.   unlink(tmp_name);    /* Make file disappear */
  444.   /*search for header line*/
  445.   for (;;) {
  446.     if (fgets(buf, sizeof buf, stdin) == NULL) {
  447.       fatal();
  448.     }
  449.     if (streq(buf, "xbtoa Begin\n")) {
  450.       break;
  451.     }
  452.   }
  453.  
  454.   while ((c = getchar()) != EOF) {
  455.     if (c == '\n') {
  456.       continue;
  457.     } else if (c == 'x') {
  458.       break;
  459.     } else {
  460.       decode(c);
  461.     }
  462.   }
  463.   if(scanf("btoa End N %ld %lx E %lx S %lx R %lx\n",
  464.          &n1, &n2, &oeor, &osum, &orot) != 5) {
  465.     fatal();
  466.   }
  467.   if ((n1 != n2) || (oeor != Ceor) || (osum != Csum) || (orot != Crot)) {
  468.     fatal();
  469.   } else {
  470.     /*copy OK tmp file to stdout*/;
  471.     fseek(tmp_file, 0L, 0);
  472.     for (i = n1; --i >= 0;) {
  473.       putchar(getc(tmp_file));
  474.     }
  475.   }
  476.   exit(0);
  477. }
  478. SHAR_EOF
  479. if test 2505 -ne "`wc -c < 'atob.c'`"
  480. then
  481.     echo shar: error transmitting "'atob.c'" '(should have been 2505 characters)'
  482. fi
  483. fi # end of overwriting check
  484. echo shar: extracting "'btoa.1'" '(2483 characters)'
  485. if test -f 'btoa.1'
  486. then
  487.     echo shar: will not over-write existing file "'btoa.1'"
  488. else
  489. sed 's/^X//' << \SHAR_EOF > 'btoa.1'
  490. X.TH BTOA 1 local
  491. X.SH NAME
  492. btoa, atob, tarmail, untarmail \- encode/decode binary to printable ASCII
  493. X.SH SYNOPSIS
  494. X.B btoa
  495. X.br
  496. X.B atob
  497. X.br
  498. X.B tarmail
  499. who subject files ...
  500. X.br
  501. X.B untarmail
  502. [ file ]
  503. X.SH DESCRIPTION
  504. X.I Btoa
  505. is a filter that reads anything from the standard input, and encodes it into
  506. printable ASCII on the standard output.  It also attaches a header and checksum
  507. information used by the reverse filter 
  508. X.I atob 
  509. to find the start of the data and to check integrity.
  510. X.PP
  511. X.I Atob
  512. reads an encoded file, strips off any leading and
  513. trailing lines added by mailers, and recreates a copy of the original file
  514. on the standard output.
  515. X.I Atob 
  516. gives NO output (and exits with an error message) if its input is garbage or 
  517. the checksums do not check.
  518. X.PP
  519. X.I Tarmail
  520. is a shell script that tar's up all the given files, pipes them 
  521. through 
  522. X.IR compress ","
  523. X.IR btoa ","
  524. and mails them to the given person with the given subject phrase.  For
  525. example:
  526. X.PP
  527. X.in 1i
  528. tarmail ralph "here it is ralph" foo.c a.out
  529. X.in -1i
  530. X.PP
  531. Will package up files "foo.c" and "a.out" and mail them to "ralph" using
  532. subject "here it is ralph".  Notice the quotes on the subject.  They are
  533. necessary to make it one argument to the shell.
  534. X.PP
  535. X.I Tarmail 
  536. with no args will print a short message reminding you what the required args 
  537. are.  When the mail is received at the other end, that person should use
  538. mail to save the message in some temporary file name (say "xx").
  539. Then saying "untarmail xx"
  540. will decode the message and untar it.  
  541. X.I Untarmail 
  542. can also be used as a filter.  By using 
  543. X.IR tarmail ","
  544. binary files and
  545. entire directory structures can be easily transmitted between machines.
  546. Naturally, you should understand what tar itself does before you use 
  547. X.IR tarmail "."
  548. X.PP
  549. Other uses:
  550. X.PP
  551. compress < secrets | crypt | btoa | mail ralph
  552. X.PP
  553. will mail the encrypted contents of the file "secrets" to ralph.  If ralph
  554. knows the encryption key, he can decode it by saving the mail (say in "xx"),
  555. and then running:
  556. X.PP
  557. atob < xx | crypt | uncompress
  558. X.PP
  559. (crypt requests the key from the terminal,
  560. and the "secrets" come out on the terminal).
  561. X.SH AUTHOR
  562. Paul Rutter (modified by Joe Orost)
  563. X.SH FEATURES
  564. X.I Btoa
  565. uses a compact base-85 encoding so that
  566. 4 bytes are encoded into 5 characters (file is expanded by 25%).
  567. As a special case, 32-bit zero is encoded as one character.  This encoding
  568. produces less output than
  569. X.IR uuencode "(1)."
  570. X.SH "SEE ALSO"
  571. compress(1), crypt(1), uuencode(1), mail(1)
  572. SHAR_EOF
  573. if test 2483 -ne "`wc -c < 'btoa.1'`"
  574. then
  575.     echo shar: error transmitting "'btoa.1'" '(should have been 2483 characters)'
  576. fi
  577. fi # end of overwriting check
  578. echo shar: extracting "'btoa.c'" '(2333 characters)'
  579. if test -f 'btoa.c'
  580. then
  581.     echo shar: will not over-write existing file "'btoa.c'"
  582. else
  583. sed 's/^X//' << \SHAR_EOF > 'btoa.c'
  584. /* btoa: version 4.0
  585.  * stream filter to change 8 bit bytes into printable ascii
  586.  * computes the number of bytes, and three kinds of simple checksums
  587.  * incoming bytes are collected into 32-bit words, then printed in base 85
  588.  *  exp(85,5) > exp(2,32)
  589.  * the ASCII characters used are between '!' and 'u'
  590.  * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data.
  591.  *
  592.  *  Paul Rutter        Joe Orost
  593.  *  philabs!per        petsd!joe
  594.  *
  595.  *  WARNING: this version is not compatible with the original as sent out
  596.  *  on the net.  The original encoded from ' ' to 't'; which cause problems
  597.  *  with some mailers (stripping off trailing blanks).
  598.  */
  599.  
  600. #include <stdio.h>
  601.  
  602. #define reg register
  603.  
  604. #define MAXPERLINE 78
  605.  
  606. long int Ceor = 0;
  607. long int Csum = 0;
  608. long int Crot = 0;
  609.  
  610. long int ccount = 0;
  611. long int bcount = 0;
  612. long int word;
  613.  
  614. #define EN(c)    (int) ((c) + '!')
  615.  
  616. encode(c) 
  617.   reg c;
  618. {
  619.   Ceor ^= c;
  620.   Csum += c;
  621.   Csum += 1;
  622.   if ((Crot & 0x80000000)) {
  623.     Crot <<= 1;
  624.     Crot += 1;
  625.   } else {
  626.     Crot <<= 1;
  627.   }
  628.   Crot += c;
  629.  
  630.   word <<= 8;
  631.   word |= c;
  632.   if (bcount == 3) {
  633.     wordout(word);
  634.     bcount = 0;
  635.   } else {
  636.     bcount += 1;
  637.   }
  638. }
  639.  
  640. wordout(word) 
  641.   reg long int word;
  642. {
  643.   if (word == 0) {
  644.     charout('z');
  645.   } else {
  646.     reg int tmp = 0;
  647.     
  648.     if(word < 0) {    /* Because some don't support unsigned long */
  649.       tmp = 32;
  650.       word = word - (long)(85 * 85 * 85 * 85 * 32);
  651.     }
  652.     if(word < 0) {
  653.       tmp = 64;
  654.       word = word - (long)(85 * 85 * 85 * 85 * 32);
  655.     }
  656.     charout(EN((word / (long)(85 * 85 * 85 * 85)) + tmp));
  657.     word %= (long)(85 * 85 * 85 * 85);
  658.     charout(EN(word / (85 * 85 * 85)));
  659.     word %= (85 * 85 * 85);
  660.     charout(EN(word / (85 * 85)));
  661.     word %= (85 * 85);
  662.     charout(EN(word / 85));
  663.     word %= 85;
  664.     charout(EN(word));
  665.   }
  666. }
  667.  
  668. charout(c) {
  669.   putchar(c);
  670.   ccount += 1;
  671.   if (ccount == MAXPERLINE) {
  672.     putchar('\n');
  673.     ccount = 0;
  674.   }
  675. }
  676.  
  677. main(argc,argv) 
  678.   char **argv;
  679. {
  680.   reg c;
  681.   reg long int n;
  682.  
  683.   if (argc != 1) {
  684.     fprintf(stderr,"bad args to %s\n", argv[0]);
  685.     exit(2);
  686.   }
  687.   printf("xbtoa Begin\n");
  688.   n = 0;
  689.   while ((c = getchar()) != EOF) {
  690.     encode(c);
  691.     n += 1;
  692.   }
  693.   while (bcount != 0) {
  694.     encode(0);
  695.   }
  696.   /* n is written twice as crude cross check*/
  697.   printf("\nxbtoa End N %ld %lx E %lx S %lx R %lx\n", n, n, Ceor, Csum, Crot);
  698.   exit(0);
  699. }
  700. SHAR_EOF
  701. if test 2333 -ne "`wc -c < 'btoa.c'`"
  702. then
  703.     echo shar: error transmitting "'btoa.c'" '(should have been 2333 characters)'
  704. fi
  705. fi # end of overwriting check
  706. echo shar: extracting "'compressdir'" '(302 characters)'
  707. if test -f 'compressdir'
  708. then
  709.     echo shar: will not over-write existing file "'compressdir'"
  710. else
  711. sed 's/^X//' << \SHAR_EOF > 'compressdir'
  712. OPTIONS=
  713. XFILES=
  714. for ARG
  715. do
  716.     case "$ARG" in
  717.     -*)    OPTIONS="$OPTIONS $ARG";;
  718.     *)    FILES="$FILES $ARG";;
  719.     esac
  720. done
  721. if test -z "$FILES"; then
  722.     FILES="."
  723. fi
  724. set $FILES
  725. find $@ -type f -links 1 -exec test -r {} -a -s {} \; \
  726. -exec expr '(' {} : '.*\.Z' ')' '=' 0 \; \
  727. -exec compress $OPTIONS {} \; >/dev/null
  728. SHAR_EOF
  729. if test 302 -ne "`wc -c < 'compressdir'`"
  730. then
  731.     echo shar: error transmitting "'compressdir'" '(should have been 302 characters)'
  732. fi
  733. chmod +x 'compressdir'
  734. fi # end of overwriting check
  735. echo shar: extracting "'compressdir.1'" '(736 characters)'
  736. if test -f 'compressdir.1'
  737. then
  738.     echo shar: will not over-write existing file "'compressdir.1'"
  739. else
  740. sed 's/^X//' << \SHAR_EOF > 'compressdir.1'
  741. X.PU
  742. X.TH COMPRESSDIR 1 local
  743. X.SH NAME
  744. compressdir, uncompressdir \-  compress and uncompress directories of files
  745. X.SH SYNOPSIS
  746. X.ll +8
  747. X.B compressdir
  748. [ flags ] [
  749. X.I "directory \&..."
  750. ]
  751. X.ll -8
  752. X.br
  753. X.B uncompressdir
  754. [ flags ] [
  755. X.I "directory \&..."
  756. ]
  757. X.SH DESCRIPTION
  758. Recursively decends each specified directory and compresses each
  759. file.
  760. Each file is replaced by a file with the extension
  761. X.B "\&.Z,"
  762. but only if the file got smaller.
  763. If no directories are specified,
  764. the compression is applied to all files starting with the current directory.
  765. Compressed files can be restored to their original form by running
  766. X.I uncompressdir
  767. on the directories.
  768. X.PP
  769. The
  770. X.I flags
  771. specified are passed to the compress(1) program.
  772. X.SH "SEE ALSO"
  773. compress(1)
  774. SHAR_EOF
  775. if test 736 -ne "`wc -c < 'compressdir.1'`"
  776. then
  777.     echo shar: error transmitting "'compressdir.1'" '(should have been 736 characters)'
  778. fi
  779. fi # end of overwriting check
  780. echo shar: extracting "'tarmail'" '(303 characters)'
  781. if test -f 'tarmail'
  782. then
  783.     echo shar: will not over-write existing file "'tarmail'"
  784. else
  785. sed 's/^X//' << \SHAR_EOF > 'tarmail'
  786. if test $# -lt 3; then
  787.   echo "Usage: tarmail mailpath \"subject-string\" directory-or-file(s)"
  788.   exit
  789. else
  790.   mailpath=$1
  791.   echo "mailpath = $mailpath"
  792.   shift
  793.   subject="$1"
  794.   echo "subject-string = $subject"
  795.   shift
  796.   echo files = $*
  797.   tar cvf - $* | compress | btoa | mail -s "$subject" $mailpath
  798. fi
  799. SHAR_EOF
  800. if test 303 -ne "`wc -c < 'tarmail'`"
  801. then
  802.     echo shar: error transmitting "'tarmail'" '(should have been 303 characters)'
  803. fi
  804. chmod +x 'tarmail'
  805. fi # end of overwriting check
  806. echo shar: extracting "'uncompressdir'" '(290 characters)'
  807. if test -f 'uncompressdir'
  808. then
  809.     echo shar: will not over-write existing file "'uncompressdir'"
  810. else
  811. sed 's/^X//' << \SHAR_EOF > 'uncompressdir'
  812. OPTIONS=
  813. XFILES=
  814. for ARG
  815. do
  816.     case "$ARG" in
  817.     -*)    OPTIONS="$OPTIONS $ARG";;
  818.     *)    FILES="$FILES $ARG";;
  819.     esac
  820. done
  821. if test -z "$FILES"; then
  822.     FILES="."
  823. fi
  824. set $FILES
  825. find $@ -type f -links 1 -exec test -r {} -a -s {} \; \
  826. -exec expr {} : '.*\.Z' \; \
  827. -exec uncompress $OPTIONS {} \; >/dev/null
  828. SHAR_EOF
  829. if test 290 -ne "`wc -c < 'uncompressdir'`"
  830. then
  831.     echo shar: error transmitting "'uncompressdir'" '(should have been 290 characters)'
  832. fi
  833. chmod +x 'uncompressdir'
  834. fi # end of overwriting check
  835. echo shar: extracting "'untarmail'" '(174 characters)'
  836. if test -f 'untarmail'
  837. then
  838.     echo shar: will not over-write existing file "'untarmail'"
  839. else
  840. sed 's/^X//' << \SHAR_EOF > 'untarmail'
  841. if test $# -ge 1; then
  842.    atob < $1 | uncompress | tar xvpf -
  843.    mv $1 /usr/tmp/$1.$$
  844.    echo tarmail file moved to: /usr/tmp/$1.$$
  845. else
  846.    atob | uncompress | tar xvpf -
  847. fi
  848. SHAR_EOF
  849. if test 174 -ne "`wc -c < 'untarmail'`"
  850. then
  851.     echo shar: error transmitting "'untarmail'" '(should have been 174 characters)'
  852. fi
  853. chmod +x 'untarmail'
  854. fi # end of overwriting check
  855. echo shar: extracting "'zcmp'" '(760 characters)'
  856. if test -f 'zcmp'
  857. then
  858.     echo shar: will not over-write existing file "'zcmp'"
  859. else
  860. sed 's/^X//' << \SHAR_EOF > 'zcmp'
  861.  
  862. OPTIONS=
  863. XFILES=
  864. for ARG
  865. do
  866.     case "$ARG" in
  867.     -*)    OPTIONS="$OPTIONS $ARG";;
  868.     *)    FILES="$FILES $ARG";;
  869.     esac
  870. done
  871. if test -z "$FILES"; then
  872.     echo "Usage: zcmp [cmp_options] file [file]"
  873.     exit 1
  874. fi
  875. set $FILES
  876. if test $# -eq 1; then
  877.     FILE=`expr $1 : '\(.*\)\.Z' '|' $1`
  878.     zcat $FILE | cmp $OPTIONS - $FILE
  879.     STAT="$?"
  880. elif test $# -eq 2; then
  881.     case "$1" in
  882.     *.Z)    case "$2" in
  883.         *.Z)    F=`basename $2 .Z`
  884.             zcat $2 > /tmp/$F.$$
  885.             zcat $1 | cmp $OPTIONS - /tmp/$F.$$
  886.             STAT="$?";;
  887.         *)    zcat $1 | cmp $OPTIONS - $2;;
  888.         esac;;
  889.     *)    case "$2" in
  890.         *.Z)    F=`basename $2 .Z`
  891.             zcat $2 > /tmp/$F.$$
  892.             cmp $OPTIONS $1 /tmp/$F.$$
  893.             STAT="$?";;
  894.         *)    cmp $OPTIONS $1 $2
  895.             STAT="$?";;
  896.         esac;;
  897.     esac
  898.     exit "$STAT"
  899. else
  900.     echo "Usage: zcmp [cmp_options] file [file]"
  901.     exit 1
  902. fi
  903. SHAR_EOF
  904. if test 760 -ne "`wc -c < 'zcmp'`"
  905. then
  906.     echo shar: error transmitting "'zcmp'" '(should have been 760 characters)'
  907. fi
  908. chmod +x 'zcmp'
  909. fi # end of overwriting check
  910. echo shar: extracting "'zcmp.1'" '(797 characters)'
  911. if test -f 'zcmp.1'
  912. then
  913.     echo shar: will not over-write existing file "'zcmp.1'"
  914. else
  915. sed 's/^X//' << \SHAR_EOF > 'zcmp.1'
  916. X.TH ZCMP 1
  917. X.SH NAME
  918. zcmp, zdiff \- compare compressed files
  919. X.SH SYNOPSIS
  920. X.B zcmp
  921. [ cmp_options ] file1
  922. [ file2 ]
  923. X.br
  924. X.B zdiff
  925. [ diff_options ] file1
  926. [ file2 ]
  927. X.SH DESCRIPTION
  928. X.I  Zcmp
  929. and 
  930. X.I zdiff
  931. are used to invoke the
  932. X.I cmp
  933. or the
  934. X.I diff
  935. program on compressed files.  All options specified are passed directly to
  936. X.I cmp
  937. or
  938. X.IR diff "."
  939. If only 1 file is specified, then the files compared are
  940. X.I file1
  941. and an uncompressed
  942. X.IR file1 ".Z."
  943. If two files are specified, then they are uncompressed (if ending with ".Z")
  944. and fed to
  945. X.I cmp
  946. or
  947. X.IR diff "."
  948. The exit status from 
  949. X.I cmp
  950. or
  951. X.I diff
  952. is preserved.
  953. X.SH "SEE ALSO"
  954. cmp(1), diff(1), zmore(1), zcat(1), compress(1), uncompress(1)
  955. X.SH BUGS
  956. Messages from the
  957. X.I cmp
  958. or
  959. X.I diff
  960. programs refer to temporary filenames instead of those specified.
  961. SHAR_EOF
  962. if test 797 -ne "`wc -c < 'zcmp.1'`"
  963. then
  964.     echo shar: error transmitting "'zcmp.1'" '(should have been 797 characters)'
  965. fi
  966. fi # end of overwriting check
  967. echo shar: extracting "'zdiff'" '(724 characters)'
  968. if test -f 'zdiff'
  969. then
  970.     echo shar: will not over-write existing file "'zdiff'"
  971. else
  972. sed 's/^X//' << \SHAR_EOF > 'zdiff'
  973.  
  974. OPTIONS=
  975. XFILES=
  976. for ARG
  977. do
  978.     case "$ARG" in
  979.     -*)    OPTIONS="$OPTIONS $ARG";;
  980.     *)    FILES="$FILES $ARG";;
  981.     esac
  982. done
  983. if test -z "$FILES"; then
  984.     echo "Usage: zdiff [diff_options] file [file]"
  985.     exit 1
  986. fi
  987. set $FILES
  988. if test $# -eq 1; then
  989.     FILE=`expr $1 : '\(.*\)\.Z' '|' $1`
  990.     zcat $FILE | diff $OPTIONS - $FILE
  991.     STAT="$?"
  992. elif test $# -eq 2; then
  993.     case "$1" in
  994.     *.Z)    case "$2" in
  995.         *.Z)    F=`basename $2 .Z`
  996.             zcat $2 > /tmp/$F.$$
  997.             zcat $1 | diff $OPTIONS - /tmp/$F.$$
  998.             STAT="$?";;
  999.         *)    zcat $1 | diff $OPTIONS - $2;;
  1000.         esac;;
  1001.     *)    case "$2" in
  1002.         *.Z)    zcat $2 | diff $OPTIONS $1 -
  1003.             STAT="$?";;
  1004.         *)    diff $OPTIONS $1 $2
  1005.             STAT="$?";;
  1006.         esac;;
  1007.     esac
  1008.     exit "$STAT"
  1009. else
  1010.     echo "Usage: zdiff [diff_options] file [file]"
  1011.     exit 1
  1012. fi
  1013. SHAR_EOF
  1014. if test 724 -ne "`wc -c < 'zdiff'`"
  1015. then
  1016.     echo shar: error transmitting "'zdiff'" '(should have been 724 characters)'
  1017. fi
  1018. chmod +x 'zdiff'
  1019. fi # end of overwriting check
  1020. echo shar: extracting "'zmore'" '(306 characters)'
  1021. if test -f 'zmore'
  1022. then
  1023.     echo shar: will not over-write existing file "'zmore'"
  1024. else
  1025. sed 's/^X//' << \SHAR_EOF > 'zmore'
  1026. XFIRST=1
  1027. for FILE
  1028. do
  1029.     if test $FIRST -eq 0; then
  1030.         echo "--More--(Next file: $FILE)\c"
  1031.         stty cbreak -echo
  1032.         ANS=`dd bs=1 count=1 2>/dev/null` 
  1033.         stty -cbreak echo
  1034.         echo " "
  1035.         if test "$ANS" = 'e'; then
  1036.             exit
  1037.         fi
  1038.     fi
  1039.     echo "------> $FILE <------"
  1040.     zcat $FILE | more
  1041.     if test -t; then
  1042.         FIRST=0
  1043.     fi
  1044. done
  1045. SHAR_EOF
  1046. if test 306 -ne "`wc -c < 'zmore'`"
  1047. then
  1048.     echo shar: error transmitting "'zmore'" '(should have been 306 characters)'
  1049. fi
  1050. chmod +x 'zmore'
  1051. fi # end of overwriting check
  1052. echo shar: extracting "'zmore.1'" '(3702 characters)'
  1053. if test -f 'zmore.1'
  1054. then
  1055.     echo shar: will not over-write existing file "'zmore.1'"
  1056. else
  1057. sed 's/^X//' << \SHAR_EOF > 'zmore.1'
  1058. X.TH ZMORE 1
  1059. X.SH NAME
  1060. zmore \- file perusal filter for crt viewing of compressed text
  1061. X.SH SYNOPSIS
  1062. X.B zmore
  1063. [ name ...  ]
  1064. X.SH DESCRIPTION
  1065. X.I  Zmore
  1066. is a filter which allows examination of compressed text files
  1067. one screenful at a time on a soft-copy terminal.
  1068. It normally pauses after each screenful, printing --More--
  1069. at the bottom of the screen.
  1070. If the user then types a carriage return, one more line is displayed.
  1071. If the user hits a space,
  1072. another screenful is displayed.  Other possibilites are enumerated later.
  1073. X.PP
  1074. X.I Zmore
  1075. looks in the file
  1076. X.I /etc/termcap
  1077. to determine terminal characteristics,
  1078. and to determine the default window size.
  1079. On a terminal capable of displaying 24 lines,
  1080. the default window size is 22 lines.
  1081. X.PP
  1082. Other sequences which may be typed when
  1083. X.I zmore
  1084. pauses, and their effects, are as follows (\fIi\fP is an optional integer
  1085. argument, defaulting to 1) :
  1086. X.PP
  1087. X.IP \fIi\|\fP<space>
  1088. display
  1089. X.I i
  1090. more lines, (or another screenful if no argument is given)
  1091. X.PP
  1092. X.IP ^D
  1093. display 11 more lines (a ``scroll'').
  1094. If
  1095. X.I i
  1096. is given, then the scroll size is set to \fIi\|\fP.
  1097. X.PP
  1098. X.IP d
  1099. same as ^D (control-D)
  1100. X.PP
  1101. X.IP \fIi\|\fPz
  1102. same as typing a space except that \fIi\|\fP, if present, becomes the new
  1103. window size.  Note that the window size reverts back to the default at the
  1104. end of the current file.
  1105. X.PP
  1106. X.IP \fIi\|\fPs
  1107. skip \fIi\|\fP lines and print a screenful of lines
  1108. X.PP
  1109. X.IP \fIi\|\fPf
  1110. skip \fIi\fP screenfuls and print a screenful of lines
  1111. X.PP
  1112. X.IP "q or Q"
  1113. quit reading the current file; go on to the next (if any)
  1114. X.PP
  1115. X.IP e
  1116. When the prompt --More--(Next file: 
  1117. X.IR file )
  1118. is printed, this command causes zmore to exit.
  1119. X.PP 
  1120. X.IP =
  1121. Display the current line number.
  1122. X.PP
  1123. X.IP \fIi\|\fP/expr
  1124. search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP
  1125. If the pattern is not found,
  1126. X.I zmore
  1127. goes on to the next file (if any).
  1128. Otherwise, a screenful is displayed, starting two lines before the place
  1129. where the expression was found.
  1130. The user's erase and kill characters may be used to edit the regular
  1131. expression.
  1132. Erasing back past the first column cancels the search command.
  1133. X.PP
  1134. X.IP \fIi\|\fPn
  1135. search for the \fIi\|\fP-th occurrence of the last regular expression entered.
  1136. X.PP
  1137. X.IP !command
  1138. invoke a shell with \fIcommand\|\fP. 
  1139. The character `!' in "command" are replaced with the
  1140. the previous shell command.  The sequence "\\!" is replaced by "!".
  1141. X.PP
  1142. X.IP ":q or :Q"
  1143. quit reading the current file; go on to the next (if any)
  1144. (same as q or Q).
  1145. X.PP
  1146. X.IP .
  1147. (dot) repeat the previous command.
  1148. X.PP
  1149. The commands take effect immediately, i.e., it is not necessary to
  1150. type a carriage return.
  1151. Up to the time when the command character itself is given,
  1152. the user may hit the line kill character to cancel the numerical
  1153. argument being formed.
  1154. In addition, the user may hit the erase character to redisplay the
  1155. --More-- message.
  1156. X.PP
  1157. At any time when output is being sent to the terminal, the user can
  1158. hit the quit key (normally control\-\\).
  1159. X.I Zmore
  1160. will stop sending output, and will display the usual --More--
  1161. prompt.
  1162. The user may then enter one of the above commands in the normal manner.
  1163. Unfortunately, some output is lost when this is done, due to the
  1164. fact that any characters waiting in the terminal's output queue
  1165. are flushed when the quit signal occurs.
  1166. X.PP
  1167. The terminal is set to
  1168. X.I noecho
  1169. mode by this program so that the output can be continuous.
  1170. What you type will thus not show on your terminal, except for the / and !
  1171. commands.
  1172. X.PP
  1173. If the standard output is not a teletype, then
  1174. X.I zmore
  1175. acts just like
  1176. X.I zcat,
  1177. except that a header is printed before each file.
  1178. X.SH FILES
  1179. X.DT
  1180. /etc/termcap        Terminal data base
  1181. X.SH "SEE ALSO"
  1182. more(1), zcat(1), compress(1), uncompress(1)
  1183. SHAR_EOF
  1184. if test 3702 -ne "`wc -c < 'zmore.1'`"
  1185. then
  1186.     echo shar: error transmitting "'zmore.1'" '(should have been 3702 characters)'
  1187. fi
  1188. fi # end of overwriting check
  1189. #    End of shell archive
  1190. exit 0
  1191.